package com.zutassociation.web.controller.system;

import com.zutassociation.common.core.controller.BaseController;
import com.zutassociation.common.core.domain.AjaxResult;
import com.zutassociation.common.core.page.TableDataInfo;
import com.zutassociation.common.utils.SecurityUtils;
import com.zutassociation.system.domain.AcUser;
import com.zutassociation.system.service.AcUserService;
import com.zutassociation.system.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评论 信息操作处理
 *
 * @author 黄玉东
 * @version 1.0
 * @date 2021/4/20 21:13
 */
@RestController
@RequestMapping("/acUser")
public class AcUserController extends BaseController {

    @Autowired
    private AcUserService acUserService;

    /**
     * 获取评论列表
     */
//    @PreAuthorize("@ss.hasPermi('system:acUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(AcUser acUser) {
        startPage();
        List<AcUser> list = acUserService.selectReplyList(acUser);
        return getDataTable(list);
    }

    /**
     * 根据发送人评论编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:acUser:query')")
    @GetMapping(value = "/userId/{userId}")
    public AjaxResult getFromInfo(@PathVariable("userId") Long userId) {
        return AjaxResult.success(acUserService.selectReplyuserId(userId));
    }


    /**
     * 根据评论编号获取详细信息
     */
    //    @PreAuthorize("@ss.hasPermi('system:acUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(acUserService.selectReplyById(id));
    }


    //    @PreAuthorize("@ss.hasPermi('system:acUser:query')")
    @GetMapping(value = "/acId/{acId}")
    public AjaxResult getForumIdInfo(@PathVariable("acId") Long acId) {
        return AjaxResult.success(acUserService.selectReplyForumId(acId));
    }

    /**
     * 新增评论
     */
//    @PreAuthorize("@ss.hasPermi('system:acUser:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody AcUser acUser) {
        acUser.setCreateBy(SecurityUtils.getUsername());
        return toAjax(acUserService.insertReply(acUser));
    }

    /**
     * 修改评论
     */
//    @PreAuthorize("@ss.hasPermi('system:acUser:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody AcUser acUser) {
        acUser.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(acUserService.updateReply(acUser));
    }




    /**
     * 删除评论
     */
//    @PreAuthorize("@ss.hasPermi('system:acUser:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(acUserService.deleteReplyByIds(ids));
    }


}
